﻿// -----------------------------------------------------------------------
// <copyright file="RTCExtensions.cs" company="Microsoft">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace RTC_Importer
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using RTC_Importer.Data;
    using System.Drawing;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public static class RTC_Extensions
    {
        public static int ToInt(this string input)
        {
            int i = 0;
            int.TryParse(input, out i);

            return i;
        }

        public static bool ToBool(this string input)
        {
            bool i = false;
            bool.TryParse(input, out i);

            return i;
        }

        public static Point ToPoint(this string input)
        {
            int i = 0;
            string[] sfield = input.Split(',');

            Point p = new Point(sfield[0].ToInt(), sfield[1].ToInt());

            return p;
        }

        public static RTC_Character To_RTC_Character(this string input)
        {
            //CHARACTER_ALEX		NAME=(ALEX)	TITLE=(ANDER)			GENDER=(M)	STATS=( 50,57,13)	EXP=(0.0,3.5,0.0,2.8)	ATTRS=(44,55,45,40,35,40)	HIDDEN=(100,100,100,100,100,100)	OTHER=(-1,-1,0,0)	BITMAPS=(PORTRAIT:BITMAP_PORTRAIT_ALEX,HAND_WEAPON:BITMAP_ICON_PARTY_HAND,HAND_MOUSE:NULL)	METHODS=(ATTACK_METHOD_PUNCH,ATTACK_METHOD_KICK,ATTACK_METHOD_WAR_CRY)	BONES=(MISC_BONES)
            string[] sField = input.Split('\t');

            RTC_Character rtcChar = new RTC_Character();

            //rtcChar.Id = sField[0];
            rtcChar.NAME = sField[2].Replace("NAME=","");
            rtcChar.TITLE = sField[3].Replace("TITLE=", "");
            rtcChar.GENDER = sField[6].Replace("GENDER=", "");
            rtcChar.STATS = sField[7].Replace("STATS=", "");
            rtcChar.EXP = sField[8].Replace("EXP=", "");
            rtcChar.ATTRS = sField[9].Replace("ATTRS=", "");
            rtcChar.HIDDEN = sField[10].Replace("HIDDEN=", "");
            rtcChar.OTHER = sField[11].Replace("OTHER=", "");
            rtcChar.BITMAPS = sField[12].Replace("BITMAPS=", "");
            rtcChar.METHODS = sField[13].Replace("METHODS=", "");
            rtcChar.BONES = sField[14].Replace("BONES=", "");

            return rtcChar;
        }
		
        public static RTC_Method To_RTC_Method(this string input)
        {
            // ADD		
			// ATTACK_METHOD_TELEPORT_PARTY_TO_DESTINATION	
			// NAME=(TELEPORT)	
			// TYPE=(NINJA)	
			// ACTION=(ACTION_OBJECT_ACTIVATE,WALLITEM_RELAY_TELEPORT,NULL)	
			// STRENGTH=(0)	
			// LEVEL=(0)	
			// ENERGY=(4)	
			// TIME=(10)	
			// CHARGES_USED=(0)	
			// MANA_USED=(0)	
			// SOUNDS=(SUCCESS:SOUND_OTHER_BUZZ,FAILURE:NULL)	

            string[] sField = input.Split('\t');

            RTC_Method rtcChar = new RTC_Method();

            rtcChar.DIRECTION = sField[0];
            rtcChar.ID = sField[1];
            rtcChar.NAME = sField[2];
            rtcChar.TYPE = sField[3];
            rtcChar.ACTION = sField[4];
            rtcChar.STRENGTH = sField[5];
            rtcChar.LEVEL = sField[6];
            rtcChar.ENERGY = sField[7];
            rtcChar.TIME = sField[9];
            rtcChar.CHAGES_USED = sField[10];
            rtcChar.MANA_USED = sField[11];
            rtcChar.SOUND_SUCCES = sField[12];
            rtcChar.SOUND_FAILURE = sField[13];

            return rtcChar;
        }		
		
		

        public static RTC_KeyValue To_RTC_KeyValue(this string input)
        {
            //NAME.............=(DUNGEON MASTER (RETURN TO CHAOS))
            string[] sField = input.Split('=');

            RTC_KeyValue kv = new RTC_KeyValue();
            if (sField.GetLength(0) == 2)
            {
                kv.Key = sField[0].Replace(".", "");
                kv.Value = sField[1].Replace("(", "").Replace(")", "");
            }
            else
                return null;

            return kv;
        }

    }

}
